package com.ruiben.mall.controller;


import com.ruiben.mall.impl.CommentServiceImpl;
import com.ruiben.mall.pojo.ShopProductComment;
import com.ruiben.mall.utils.CommonJSONResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("comment")
public class CommentController {

    @Autowired
    private CommentServiceImpl commentService;

    @PostMapping("addComment")
    public CommonJSONResult addComment(String userOrderProductId,ShopProductComment comment,String[] imgs){

        if (StringUtils.isBlank(comment.getUserid()) || comment.getUserid().equals("undefined")){
            return CommonJSONResult.errorMsg("用户id不能为空");
        }

        if (StringUtils.isBlank(comment.getProductid()) || comment.getProductid().equals("undefined")){
            return CommonJSONResult.errorMsg("商品id不能为空");
        }

        if (StringUtils.isBlank(comment.getOrderno()) || comment.getOrderno().equals("undefined")){
            return CommonJSONResult.errorMsg("订单编号不能为空");
        }

        if (StringUtils.isBlank(comment.getComment()) || comment.getComment().equals("undefined")){
            return CommonJSONResult.errorMsg("评论内容不能为空");
        }

        if (StringUtils.isBlank(userOrderProductId) || userOrderProductId.equals("undefined")){
            return CommonJSONResult.errorMsg("订单商品id不能为空");
        }

        boolean b = commentService.addComment(userOrderProductId,comment,imgs);
        if (b) {
            return CommonJSONResult.ok();
        }

        return CommonJSONResult.errorMsg("评论失败");


    }

}
